<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>类的基本知识</title>
  </head>
  <body>
    <script type="text/javascript">
      // 创建一个类
      class Person {
        constructor(name, age) {
          this.name = name;
          this.age = age;
        }
        sayName() {
          console.log(this.name);
        }
        sayAge() {
          console.log(this.age);
        }
      }
      //继承
      class Student extends Person {
        constructor(name, age, grade) {
          super(name, age);
          this.grade = grade;
        }
        sayGrade() {
          console.log(this.name + this.age + this.grade);
        }
        sayName() {
          console.log(this.name + "-------------重写父类方法");
        }
      }

      // 类的实例化
      const p = new Person("张三", 18);
      const s = new Student("李四", 19, "一年级");
      p.sayName();
      p.sayAge();
      s.sayGrade();
      s.sayName();
    </script>
  </body>
</html>
